export default {
  namespaced: true,
  state: () => ({
    userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
    token: uni.getStorageSync('token') || '',
    isLogin: uni.getStorageSync('isLogin') || false,
    usersex: uni.getStorageSync('usersex') || 0,
    username: uni.getStorageSync('username') || ' ',
    userphone: uni.getStorageSync('userphone') || ' ',
    useraddress: uni.getStorageSync('useraddress') || '',
    useremail: uni.getStorageSync('useremail') || ' ',
    userid: uni.getStorageSync('userid') || '',
    messageNum: uni.getStorageSync('messageNum') || 'dot'
  }),
  mutations: {
    updateMessageNum(state,messageNum) {
      state.messageNum = messageNum
      this.commit('user_module/saveMessageNum')
    },
    saveMessageNum(state) {
      uni.setStorageSync('messageNum',JSON.stringify(state.messageNum))
    },
    updateisLogin(state,isLogin) {
      state.isLogin = isLogin
      this.commit('user_module/saveisLogin')
    },
    saveisLogin(state) {
      uni.setStorageSync('isLogin',JSON.stringify(state.isLogin))
    },
    updateUserInfo(state,userinfo) {
      state.userinfo = userinfo
      this.commit('user_module/saveUserinfo')
    },
    saveUserinfo(state) {
      uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))
    },
    updateUserId(state,userid) {
      state.userid = userid
      this.commit('user_module/saveUserId')
    },
    saveUserId(state) {
      uni.setStorageSync('userid',state.userid)
    },
    updateToken(state,token) {
      state.token = token
      this.commit('user_module/saveToken')
    },
    saveToken(state) {
      uni.setStorageSync('token',JSON.stringify(state.token))
    },
    updateUserName(state,username) {
      state.username = username
      this.commit('user_module/saveUserName')
    },
    saveUserName(state) {
      uni.setStorageSync('username',state.username)
    },
    updateUserPhone(state,userphone) {
      state.userphone = userphone
      this.commit('user_module/saveUserPhone')
    },
    saveUserPhone(state) {
      uni.setStorageSync('userphone',state.userphone)
    },
    updateUserAddress(state,address) {
      state.address = address
      this.commit('user_module/saveUserAddress')
    },
    saveUserAddress(state) {
      uni.setStorageSync('address',JSON.stringify(state.address))
    },
    updateUserEmail(state,useremail) {
      state.useremail = useremail
      this.commit('user_module/saveUserEmail')
    },
    saveUserEmail(state) {
      uni.setStorageSync('useremail',state.useremail)
    },
    updateUserSex(state,usersex) {
      state.usersex = usersex
      this.commit('user_module/saveUserSex')
    },
    saveUserSex(state) {
      uni.setStorageSync('usersex',state.usersex)
    },
    showLoginInfo() {
          uni.showModal({
            title: '提示',
            content: '请您先登录！',
            showCancel: false,
            success: (res) => {
              wx.switchTab({
                url: '../mine/mine',
              });
            },
            fail: (res) => {
              console.log("弹窗出现错误！");
            },
          })
        }
    },
  getter: {
    
  }
}